
opts=OptionParser(version='%prog 0.1', usage="%prog [TARGET] [OPTIONS]", description='Simple build tool written in Python. Useful in small projects where overbloated features of make, jam & co are unnecessary. build.py uses external configuration files called buildfiles, similar to Makefiles and Jamfiles. See docs for more info.')

opts.set_defaults(file='Buildfile')
opts.add_option('-f','--file',dest='file',help='set buildfile path. Default : \'buildfile\'')

"""opts.add_option('-G','--Get',action='store_const',const='G',dest='mode',help='Get mangas from server')
opts.add_option('-Q','--Query',action='store_const',const='Q',dest='mode',help='Query info about mangas from server')
opts.add_option('-m','--manga',dest='manga',help='Select manga which has NAME as a keyword (See also -Q option)',metavar='NAME')
opts.add_option('-c','--chapter',dest='chapter',help='Query/get manga from chapter specified by NUM',metavar="NUM")
opts.add_option('-r','--range',dest='range',help='Query/get range of chapters specified by RANGE (format: START-END)',metavar="RANGE")
opts.add_option('-a','--all',action="store_true",dest='all',help='Query/get all chapters of manga')
"""
TARGETS=[]

opt=opts.parse_args(sys.argv[1:])
opt=opt[0]

for a in sys.argv[1:]:
	if a[0]=='-': break
	TARGETS.append(a)

if len(TARGETS)==0:
	TARGETS=['build']

if not os.path.exists(opt.file):
	error('Buildfile '+opt.file+' does not exist.')

execfile(opt.file)
package(Option().default_package)
for t in TARGETS:
	target(t)
